package com.anyikang.volunteer.sos.volunteer.jpush;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.anyikang.volunteer.sos.volunteer.R;

import org.json.JSONObject;

import cn.jpush.android.api.JPushInterface;

public class PushNotifyDetailActivity extends AppCompatActivity {

    String TAG = "PushNotifyDetail"+"_gxw";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_push_notify_detail);
        initView();
    }

    private void initView() {


        //标题栏
       /*   TextView tvTitle = (TextView) this.findViewById(R.id.tvHeadTitle);
        tvTitle.setText("代付通知");
        ImageView imvBack = (ImageView) this.findViewById(R.id.imvBack);
        imvBack.setOnClickListener(this);

      btGoPay = (Button) this.findViewById(R.id.btGoPay);
        btGoPay.setOnClickListener(this);*/

        Intent intent = getIntent();
        if (null != intent) {
            //解析推送过来的字段
            Bundle bundle = getIntent().getExtras();
            String msgTitle = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
            String msgContent = "";
            String msgExtra = "";
            String msgTime = "";
            if (!TextUtils.isEmpty(msgTitle)) {
                msgContent = bundle.getString(JPushInterface.EXTRA_ALERT);
                msgExtra = bundle.getString(JPushInterface.EXTRA_EXTRA);
                Log.i(TAG, msgExtra);
                try {
                    JSONObject extra = new JSONObject(msgExtra);
                    //在这里解析extra，服务端自定义数据的下发
                   /* paySn = extra.getString("pay_sn");
                    totalPrice = extra.getString("total_price");
                    msgTime = Utils.StringToTime(extra.getString("inputtime"));*/
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {//消息中心传递过来的字段
       /*         msgTitle = bundle.getString("title");
                msgContent = bundle.getString("content");
                paySn = bundle.getString("pay_sn");
                totalPrice = bundle.getString("total_price");
                msgTime =bundle.getString("time");*/
            }

            //时间
            TextView tvMsgTime = (TextView) this.findViewById(R.id.tvMsgTime);
            tvMsgTime.setText(msgTime);

            //标题和内容
            TextView tvMsgTitle = (TextView) this.findViewById(R.id.tvMsgTitle);
            tvMsgTitle.setText(msgTitle);
            TextView tvMsgContent = (TextView) this.findViewById(R.id.tvMsgContent);
            tvMsgContent.setText(msgContent);

            //打印日志
            String log = "title=" + msgTitle + ",content=" + msgContent + ",extra=" + msgExtra;
            Log.i(TAG, log);
        }
    }



}
